/**
 * 全局的js
 */
$(function() {
	// 头部宣传图片轮播
	rotateBanners();
});

/**
 * 设置页面语言
 * @param {} language， 如：zh_CN
 */
function setLanguage(language) {
	var url = window.ctx + '/setLanguage.htm?request_locale=' + language;
	$.getJSON(url, function(feedback) {
		window.location.reload();
	});
}

function rotateBanners() {
	var t = 10000, btns = $('#banner-btns a'), len = btns.length;
	var bannerIndex = 0;
	if (!len) {
		return false;
	}
	$$setInter = setInterval(funSetime = function() {
				bannerIndex++;
				if (bannerIndex >= len) {
					bannerIndex = 0;
				};
				showBanner(bannerIndex);
	}, t);
	var showBanner = function(n) {
		for (var i = len - 1; i >= 0; i--) {
			btns.get(i).className = '';
			$('#banner-' + i).hide();
		}
		btns.get(n).className = 'on';
		$('#banner-' + n + ' img').fadeIn('normal');
		$('#banner-' + n).show();
	};
	btns.each(function(i) {
		$(this).data('i', i);
		$(this).mouseover(function() {
					clearInterval($$setInter);
					showBanner($(this).data('i'));
		}).click(function() {
			return false;
		}).focus(function() {
			this.blur();
		}).mouseout(function() {
			bannerIndex = $(this).data('i');
			$$setInter = setInterval(funSetime = function() {
						bannerIndex++;
						if (bannerIndex >= len) {
							bannerIndex = 0;
						};
						showBanner(bannerIndex);
			}, t);
		});
	});
}